/*
 * Copyright Notice ====================================================
 * This file contains proprietary information of JeeStrap Co.
 * Copying or reproduction without prior written approval is prohibited.
 * Copyright (c) 2014 All rights reserved. =============================
 */

package com.jeestrap.common.smartcoder.database;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;

import com.jeestrap.common.smartcoder.domain.DriverInfo;

public class DriverInfoLoader {

	private static final String FILE = "driver.properties";

	public static List loadJDBCInfo() {
		try {
			InputStream localInputStream = DriverInfoLoader.class.getClassLoader().getResourceAsStream(FILE);
			Properties localProperties = new Properties();
			localProperties.load(localInputStream);
			return resolveJDBCInfo(localProperties);
		} catch (IOException localIOException) {
			System.out.println(localIOException.getMessage());
		}
		return new ArrayList();
	}

	private static List resolveJDBCInfo(Properties paramProperties) {
		ArrayList localArrayList = new ArrayList();
		Enumeration localEnumeration = paramProperties.keys();
		while (localEnumeration.hasMoreElements()) {
			String str1 = (String)localEnumeration.nextElement();
			int i = str1.indexOf(".");
			if (i != -1) {
				String str2 = str1.substring(0, i);
				String str3 = paramProperties.getProperty(str2 + ".Name");
				if (str3 == null)
					str3 = str2;
				String str4 = paramProperties.getProperty(str2 + ".Driver");
				String str5 = paramProperties.getProperty(str2 + ".URL");
				String str6 = paramProperties.getProperty(str2 + ".User");
				String str7 = paramProperties.getProperty(str2 + ".Password");
				DriverInfo localDriverInfo = new DriverInfo(str2, str3, str4, str5, str6, str7);
				if (!localArrayList.contains(localDriverInfo))
					localArrayList.add(localDriverInfo);
			}
		}
		Collections.sort(localArrayList);
		return localArrayList;
	}
}
